// pages/index/index.js
const db = wx.cloud.database().collection('apply').orderBy('time', 'desc')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    background: ['../../img/1.jpg', '../../img/2.jpg', '../../img/3.jpg', '../../img/4.jpg', '../../img/5.jpg'],
    list: [],
    isred: true
  },
  showmess: function (e) {
    wx.navigateTo({
      url: '/pages/detail/detail?id=' + e.currentTarget.id,
    })
  },
  myapply: function () {
    const that = this
    var user = wx.getStorageSync('user')
    db.where({
      stu: user
    }).get({
      success: function (res) {
        console.log(res)
        that.setData({
          list: res.data,
          isred: true
        })
      }
    })
  },
  unapply: function () {
    const that = this
    var user = wx.getStorageSync('user')
    db.where({
      stu: user,
      status: '审批中'
    }).get({
      success: function (res) {
        console.log(res)
        that.setData({
          list: res.data,
          isred: false
        })
      }
    })
  },

  apply: function () {
    wx.navigateTo({
      url: '/pages/apply/apply',
    })
  },
  onShow: function () {

    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0,
        list: [{
            "pagePath": "/pages/index/index",
            "text": "首页",
            "iconPath": "/img/index.png",
            "selectedIconPath": "/img/index_active.png"
          },
          {
            "pagePath": "/pages/my/my",
            "text": "我的",
            "iconPath": "/img/my.png",
            "selectedIconPath": "/img/my_active.png"
          }
        ]
      })
    }
    const that = this
    var user = wx.getStorageSync('user')
    db.where({
      stu: user
    }).get({
      success: function (res) {
        console.log(res)
        that.setData({
          list: res.data
        })
      }
    })
  }
})